<template>
  <div class="loginForm">
    <el-form :model="loginFormData">
      <el-form-item label="用户名">
        <el-input
          v-model="loginFormData.username"
          placeholder="请输入内容"
        ></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          v-model="loginFormData.password"
          placeholder="请输入内容"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="loginSubmit(loginForm)"
          >login</el-button
        >&nbsp;
        <router-link to="/register">
          <el-button type="primary">register</el-button>
        </router-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { reactive } from "vue";
import { login } from "../../api/client";
export default {
  name: "login",
  setup() {
    const loginFormData = reactive({ username: "", password: "" });
    function loginSubmit(data) {
      console.log(data.username, data.password);
      login(data).then((res) => {
        console.log(res);
        if (res?.data?.msg == 200) {
          // let nowDate = new Date().getTime() + 1000 * 60 * 60 * 24; //有效期为1天
          let storageData = { value: res.data.authorToken };
          sessionStorage.setItem("Autorization", JSON.stringify(storageData));
        }
      });
    }
    return { loginFormData, loginSubmit };
  },
};
</script>

<style scoped>
.loginForm {
  margin: 100px auto;
  padding: 10px;
  width: 700px;
  height: 300px;
  border: 1px solid black;
}
</style>